package com.kingint.web.dueros.executor;

import com.kingint.web.dueros.model.CallBackRequest;
import com.kingint.web.dueros.model.CallBackResponse;
import com.kingint.web.dueros.model.CommandNameEnum;
import com.kingint.web.dueros.model.DataMasg;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Component
public class commandExecutionService {

    @Resource
    private List<CommandExecutor> commandNameEnumList;

    private Map<CommandNameEnum, CommandExecutor> commandExecutorMap;

    @PostConstruct
    public void setup() {
        commandExecutorMap = new HashMap<CommandNameEnum, CommandExecutor>();
        for (CommandExecutor commandExecutor : commandNameEnumList) {
            commandExecutorMap.put(commandExecutor.support(), commandExecutor);
        }
    }

    public DataMasg executeCommand(CallBackRequest callBackRequest) {
//        System.out.println(commandNameEnumList);
//        System.out.println(commandExecutorMap);
//        System.out.println(commandExecutorMap.get(callBackRequest.getIntents().getName()));
//        System.out.println(commandExecutorMap.get(CommandNameEnum.checkOut));
        return commandExecutorMap.get(CommandNameEnum.valueOf(callBackRequest.getIntents().getName())).executeCommand(callBackRequest);
    }

//    public CallBackResponse executeCommand(String shopid ,String roomNum , String content){
//        return
//    }
}
